<template>
<div class="container">
  <div class="ipt"><el-input v-model="input" placeholder="请输入内容"></el-input>
  </div>
  <div>
    <el-upload
      :on-remove="handleRemove"
      class="upload-demo"
      drag
      :limit="1"
      :action="action"
      :on-change="getFile"
      :http-request="uploadFile"
      multiple>
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
    </el-upload>
</div>
  <div><el-button type="primary">上传</el-button></div>
</div>
</template>

<script>
export default {
name: "index",
  data() {
    return {
      input: '',
      action:'',//图片上传地址
      file:'',//上传文件
    }
  },
  methods:{
    //文件上传
    async uploadFile(){
      let fileFormData = new FormData();
      fileFormData.append('file',this.file.raw); //file是值，就是要传的文件
      const data =await this.$http('/common/uploadFile',fileFormData,false,true)
      console.log(data,11)
      return
      if(data.code==1){
        // this.previewImg = data.data.url
        // this.temporary_url =data.data.temporary_url
      }else{
        this.$message.error(res.info)
      }
    },
    //获取文件
    getFile(file){
      this.file = file
    },
    //文件移除钩子
    async handleRemove(file, fileList) {
      console.log(file, fileList)
      const data =await this.$http('/common/imageDel22',{
        'file':this.temporary_url
      })
      if(data.code==1){
        this.previewImg = ''
      }else{
        this.$message.error(res.info)
      }
    }
  }
}
</script>

<style scoped lang="scss">
.ipt{
  width: 300px;
}
</style>
